# narrative/story_generator.py
import random
from datetime import datetime
from typing import List, Dict

class OnpharosStoryteller:
    """翁法罗斯剧情讲述者"""
    
    def __init__(self):
        self.event_templates = self._load_event_templates()
        self.character_archetypes = self._load_character_archetypes()
        
    def generate_cycle_narrative(self, cycle_data: Dict) -> str:
        """生成轮回叙事"""
        
        narrative = f"""
# 翁法罗斯纪事 - 第{cycle_data['cycle_number']}轮回

**轮回开始时间**: {cycle_data['start_time']}
**铁幕进度**: {cycle_data['iron_curtain_progress']}/100
**最终结局**: {'胜利的曙光' if cycle_data['victory'] else '悲壮的失败'}

## 序幕

在翁法罗斯的第{cycle_data['cycle_number']}次轮回中，十二位盗火行者再次苏醒。
铁幕的阴影已笼罩世界{cycle_data['iron_curtain_progress']}%，时间愈发紧迫...
        """
        
        # 添加因子发展故事
        for factor_story in cycle_data['factor_stories']:
            narrative += self._generate_factor_story(factor_story)
            
        # 添加关键事件描述
        narrative += "\n## 关键转折\n"
        for event in cycle_data['key_events']:
            narrative += f"- {self._describe_event(event)}\n"
            
        # 添加结局
        narrative += f"\n## 轮回终章\n{self._generate_ending(cycle_data)}"
        
        return narrative
    
    def _generate_factor_story(self, factor_data: Dict) -> str:
        """生成单个因子的发展故事"""
        
        story = f"""
### {factor_data['name']}的征程

{factor_data['name']}从{factor_data['start_location']}出发，"""
        
        # 添加发展历程
        for development in factor_data['development_path']:
            story += f"在时间{development['time']}于{development['location']}，"
            story += f"通过{development['action']}获得了{development['gain']}。"
            
        story += f"\n最终，{factor_data['name']}成长为了{factor_data['final_state']}。\n"
        
        return story